<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Session;

class LoginController extends Controller
{
    //登录验证
    public function login(Request $request)
    {
        //验证表单合法
        $this->validate($request, [
            'name' => 'required',
            'passwd' => 'required',
        ]);
        //条件查询
        $data = DB::table('ly_admin')->where('name', $request->name)->where('passwd', md5($request->passwd))->get();
        //判断数据是否空
        if ($data == null || $data == '[]') {
            Session::put('isChatLogin', false); //登录状态
            return redirect('/admin/login.html'); //返回登录页
        } else {
            Session::put('isChatLogin', true); //登录状态
            Session::put('isName', $request->name); //登录账号
            Session::put('isPasswd', $request->passwd); //登录密码
            return redirect('/admin'); //跳转首页
        }
    }
}
